﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Runtime.InteropServices; 
using LEDHelper;
using LEDManager;
using LEDDataBase;
using System.Data;

namespace LEDContract
{ 
    public partial class WXLED
    { 
        LEDConsole ledctrl;
        public WXLED()
        {
            
        } 
        /// <summary>
        /// 读取所有的LED列表，加入到字典中，并且根据他们的设定进行初始化
        /// </summary>
        /// <returns></returns>
        public Int32 InsigmaLEDDriver_Init()
        {
            Int32 result = -1;
            try
            {
                if (ledctrl == null)
                {
                    ledctrl = new LEDConsole();
                    ledctrl.Show();
                }      
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
                result = -1;
            }
            result = 0;
            return result;
        } 
        public void InsigmaLEDDriver_Cleanup()
        {
            try
            {
                ledctrl.Close();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void LED_RegLED(Dictionary<string,string>LEDPara)
        {
            ledctrl.AddLED(LEDPara);
        }
        public string LED_GetLEDList()
        {
            return ledctrl.GetLEDList();
        }
        public string LEDGetIP(int nLEDID)
        {
            return ledctrl.LEDGetIP(nLEDID);
        }

        public Int32 LED_CopyScreen(int nLEDID)
        {
            Int32 result = 0; 
            try
            {
                result = ledctrl.LED_CopyScreen(nLEDID);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }
      ///
      /// 3.3	检查LED设备是否正常
      /// 定义：int LED_IsDeviceOK( int nLEDID );
      /// 功能：检测指定的屏幕显示设备是否正常运行
      /// 输入：nLEDID - 设备ID；
      /// 返回：0表示正常， -1表示出现异常。
        public Int32 LED_IsDeviceOK(int nLEDID)
        {
            Int32 result = 0; 
            try
            {
                result = ledctrl.LED_IsDeviceOK(nLEDID);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }
        public Int32 LED_SwitchPower(int nLEDID, int nTurnOn)
        {
            Int32 result = 0; 
            try
            {
                result = ledctrl.LED_SwitchPower(nLEDID, nTurnOn);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }
        /// <summary>
        /// 函数：long LED_IsDeviceTurnOn( int nLEDID );
        /// 功能：查询远程显示设备是否打开；
        /// 输入：nLEDID - 设备ID；
        /// 返回：成功返回0，失败返回-1。
        /// </summary>
        /// <param name="nLEDID"></param>
        /// <returns></returns>
        public Int32 LED_IsDeviceTurnOn(int nLEDID)
        {
            Int32 result = 0;
            try
            {
                result = ledctrl.LED_IsDeviceTurnOn(nLEDID);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return result;
        }
        ///3.6 检测设备是否离线
        ///定义: int LED_IsDeviceOffline( int nLEDID );
        ///功能: 检测指定的LED显示屏设备是否处于离线状态
        ///输入: nLEDID – 设备ID号
        ///返回: 0 表示离线 1 表示在线
        public Int32 LED_IsDeviceOffline(int nLEDID)
        {
            Int32 result = 0;
            try
            {
                result = ledctrl.LED_IsDeviceTurnOn(nLEDID);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return result;
        }

        /// <summary>
        /// 屏幕亮度控制
        /// </summary>
        /// <param name="nLEDID"></param>
        /// <param name="lValue"></param>
        /// <returns></returns>
        public Int32 LED_SetBright(int nLEDID, Int32 lValue)
        {
            Int32 result = 0;
            try
            {
                result = ledctrl.LED_SetBright(nLEDID, lValue);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return result;
        }

        /// <summary>
        /// 3.7 获取屏幕亮度
        /// 函数：long LED_GetBright( int nLEDID );
        /// 功能：获取远程显示屏的亮度值
        /// 输入：nLEDID - 设备ID
        /// 返回：long 获取到的亮度值
        /// </summary>
        /// <param name="nLEDID"></param>
        /// <returns></returns>
        public Int32 LED_GetBright(int nLEDID)
        {
            Int32 result = 0;
            try
            {
                result = ledctrl.LED_GetBright(nLEDID);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return result;
        }

        public Int32 LED_Restart(int nLEDID)
        {
            Int32 result = 0;
            try
            {
                result = ledctrl.LED_Restart(nLEDID);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return result;
        }
        public int LED_AdjustCurrentTime(int nLEDID)
        {
            Int32 result = 0;
            try
            {
                result = ledctrl.LED_AdjustCurrentTime(nLEDID);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }

        public int LED_PreUploadBMP(int nLEDID, string szBmpFile)
        {  
            Int32 result = 0;
            try
            {
                result = ledctrl.LED_PreUploadBMP(nLEDID, szBmpFile);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }
        public int LED_RemoveUploadedBmp(int nLEDID, string szBmpFile)
        {
            Int32 result = 0;
            try
            {
                result = ledctrl.LED_RemoveUploadedBmp(nLEDID, szBmpFile);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }
        public Int32 LED_GetFreeUploadBmpSpace(int nLEDID)
        {

            Int32 result = 0;
            try
            {
                result = ledctrl.LED_GetFreeUploadBmpSpace(nLEDID);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        } 
        ///3.14	屏幕初始化
        ///定义: int LED_LEDScreenInit( int nLEDID, int nScreenType, int nWidth, int nHeight );
        ///功能: 在每一次准备向指定屏幕下发数据前，对屏幕进行的初始化操作调用
        ///输入: nLEDID – 设备ID号
        ///nScreenType – 屏幕类型(目前为异步屏协议，该参数可忽略)
        ///nWidth – 屏幕宽度
        ///nHeight – 屏幕高度
        ///返回：成功返回0，失败返回-1
        public   Int32 LED_LEDScreenInit(int nLEDID, int nScreenType, int nWidth, int nHeight)
        {
            Int32 result = 0;
            try
            {
                result = ledctrl.LED_LEDScreenInit(nLEDID,nScreenType,nWidth,nHeight);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }
        public Int32 LED_BeginProgram(int nLEDID, Int32 lDisplayTime, string szBackBMP)
        {
            Int32 result = 0;
            try
            {
                result = ledctrl.LED_BeginProgram(nLEDID, lDisplayTime,szBackBMP);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }
        public void LED_AddTextBlock(int nLEDID, string szText, LEDBlock rect, ref FontDescriptor lpFont, int nEffectType, int nSpeed, Int32 lTrasnparent)
        {
            try
            { 
                ledctrl.LED_AddTextBlock(nLEDID, szText, rect, ref lpFont, nEffectType, nSpeed, lTrasnparent); 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return;
        }
        public Int32 LED_AddBmpBlock(int nLEDID, string szBmpFile, LEDBlock destRect, LEDBlock sourceRect, int nEffectType, int nSpeed, Int32 lTrasnparent)
        {  
            Int32 result = 0;
            try
            { 
              ledctrl.LED_AddBmpBlock(nLEDID, szBmpFile, destRect, sourceRect, nEffectType, nSpeed, lTrasnparent);
              
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }

        public void LED_AddClockBlock(int nLEDID, LEDBlock rect, ref ClockDescriptor lpClock, ref FontDescriptor lpFont, int nEffectType, int nSpeed, Int32 lTrasnparent)
        {
            Int32 result = 0;
            try
            {
                ledctrl.LED_AddClockBlock(nLEDID, rect, ref lpClock, ref lpFont, nEffectType, nSpeed, lTrasnparent);
                result = 0;
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return; 
        }
        public Int32 LED_EndProgram(int nLEDID)
        {
            int result = 0;

            try
            {
                result = ledctrl.LED_EndProgram(nLEDID);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }
        public int LED_SendToScreen(int nLEDID)
        {
            int result = 0;

            try
            {
                result = ledctrl.LED_SendToScreen(nLEDID);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }

        public Int32 LED_FastenProgram(int nLEDID)
        {
            Int32 result = 0;
            try
            {
                result = ledctrl.LED_FastenProgram(nLEDID);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            result = 0;
            return result;
        }
        /*
        public   Int32 LED_LEDClear(int nLEDID)
        {
            Int32 result = 0;

            try
            {

            }
            catch (Exception ex)
            {
            }
            return result;
        }        
          
        public   void LED_AddLine(int nLEDID, int x0, int y0, int x1, int y1, Int32 lColor)
        {
            Int32 result = 0;

            try
            {

            }
            catch (Exception ex)
            {
            }
            return;
        }
        
        public   void LED_AddAnimationBlock(int nLEDID, string szPath, int nDir, LEDBlock rcRect)
        {
            Int32 result = 0;

            try
            {

            }
            catch (Exception ex)
            {
            }
            return;
        }
        
        public   void LED_AddVideoBlock(int nLEDID, string szPath, LEDBlock rcRect)
        {
            Int32 result = 0;

            try
            {

            }
            catch (Exception ex)
            {
            }
            return;
        }
         
        public   int LED_DeleteProgram(int nLEDID, int nProgramID)
        {
            int result = 0;

            try
            {

            }
            catch (Exception ex)
            {
            }
            return result;
        }
         
        public   Int32 LED_RunProgram(int nLEDID, int nProgramID)
        {
            Int32 result = 0;

            try
            {

            }
            catch (Exception ex)
            {
            }
            return result;
        }
         * */
    } 
}
